package com.zgzg.shop.pay.base.utils;

import com.zgzg.shop.pay.base.Result;
import com.zgzg.shop.pay.base.enums.ApiCode;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.Map;

/**
 *
 */
public class ResponseEntityUtil {
    protected ResponseEntity<Result> renderOk() {
        return renderOk(null);
    }

    protected ResponseEntity<Result> renderOk(Map<String, Object> data) {
        Result Result = new Result(ApiCode.OK, data);
        return new ResponseEntity<>(Result, HttpStatus.OK);
    }

    public ResponseEntity<Result> renderOk(Object data) {
        Result Result = new Result(ApiCode.OK, data);
        return new ResponseEntity<>(Result, HttpStatus.OK);
    }

    protected ResponseEntity<Result> renderError(ApiCode apiCode) {
        Result Result = new Result(apiCode, null);
        return new ResponseEntity<>(Result, HttpStatus.OK);
    }

    public ResponseEntity<Result> renderError(ApiCode apiCode, String explanation) {
        Result Result = new Result(apiCode, explanation, null);
        return new ResponseEntity<>(Result, HttpStatus.OK);
    }

    protected ResponseEntity<Map<String, Object>> render(Map<String, Object> map) {
        return new ResponseEntity<>(map, HttpStatus.OK);
    }
}
